#include "pwddialog.h"
#include "ui_pwddialog.h"
#include "authoritymanager.h"
#include <QMessageBox>
PwdDialog::PwdDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PwdDialog)
{
    ui->setupUi(this);
	setWindowFlags(Qt::WindowCloseButtonHint | Qt::Dialog);
    connect(ui->pushButton, &QPushButton::clicked, [=](){
        AuthorityManager *m = AuthorityManager::getInstance();
        bool b = m->checkUserPwd(ui->userLineEdit->text(), ui->pwdLineEdit->text());
        if (b)
        {
            QDialog::accept();
        }
        else
        {
            QMessageBox box(QMessageBox::Warning, tr("Error"), tr("Please input correct password！"));
            box.setStandardButtons (QMessageBox::Ok);
            box.setButtonText (QMessageBox::Ok, tr(" OK "));
            box.exec();

            ui->pwdLineEdit->clear();
            ui->pwdLineEdit->setFocus();
        }

    });
    connect(ui->pushButton_2, &QPushButton::clicked, [=](){
        QDialog::reject();
    });
}

PwdDialog::~PwdDialog()
{
    delete ui;
}
